<?php 
	include_once('configure.php');
	
	function tep_db_connect($server = DB_SERVER, $username = DB_SERVER_USERNAME, $password = DB_SERVER_PASSWORD, $database = DB_DATABASE, $link = 'db_link') 
	{		
		global $$link;
		if (USE_PCONNECT == 'true') {
		  $$link = mysql_pconnect($server, $username, $password);
		} else {
		  $$link = mysql_connect($server, $username, $password);
		}
		mysql_set_charset('utf8',$$link);// hien thi du lieu tieng viet
		if ($$link) mysql_select_db($database);

		return $$link;
	}
	function tep_db_close($link = 'db_link') {
    global $$link;
    return mysql_close($$link);
  }
	function tep_db_error($query, $errno, $error) 
	{ 
		die('<font color="#000000"><b>' . $errno . ' - ' . $error . '<br><br>' . $query . '<br><br><small><font color="#ff0000">[TEP STOP]</font></small><br><br></b></font>');
	}
	function tep_db_query($query, $link = 'db_link') 
	{
		global $$link;

		if (defined('STORE_DB_TRANSACTIONS') && (STORE_DB_TRANSACTIONS == 'true')) {
		  error_log('QUERY ' . $query . "\n", 3, STORE_PAGE_PARSE_TIME_LOG);
		}
		$result = mysql_query($query, $$link) or tep_db_error($query, mysql_errno(), mysql_error());
		if (defined('STORE_DB_TRANSACTIONS') && (STORE_DB_TRANSACTIONS == 'true')) {
		   $result_error = mysql_error();
		   error_log('RESULT ' . $result . ' ' . $result_error . "\n", 3, STORE_PAGE_PARSE_TIME_LOG);
		}
		return $result;
	}
	function tep_db_fetch_array($db_query) {
    return mysql_fetch_array($db_query, MYSQL_ASSOC);
  }

  function tep_db_num_rows($db_query) {
	return mysql_num_rows($db_query);
  }
?>